#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        int counts = 0;
        /* 前缀和数组 */
        vector<int> sumNums;
        sumNums.push_back(0);
        for (int idx = 0; idx < nums.size(); idx++) {
            sumNums.push_back(sumNums.back() + nums[idx]);
        }
        /* 循环前缀和数组 */
        for (int loop = 0; loop < sumNums.size(); loop++) {
            for (int idx = 0; idx < loop; idx++) {
                if (sumNums[loop] - sumNums[idx] == k) {
                    counts++;
                }
            }
        }
        return counts;
    }
};

int main()
{   
    Solution s;
    vector<int> vt{1, 2, 3};
    int k = 3;
    cout << s.subarraySum(vt, k) << endl;
    return 0;
}